
//
//  FeadbackDetailViewController.m
//  BOSS-SOOC
//
//  Created by apple on 16/8/26.
//  Copyright © 2016年 Gcx. All rights reserved.
//
#define normalColor [UIColor colorWithRed:26.0/255 green:151.0/255 blue:233.0/255 alpha:1.0f]


#import "FeadbackDetailViewController.h"
#import "OptionModel.h"
#import "OptionHeaderView.h"
#import "FeedbackDetailTableView.h"
#import "SCTypeBtn.h"
#import "JSTextView.h"

@interface FeadbackDetailViewController()<UITextViewDelegate>{

    OptionModel             *_myModel;
    OptionHeaderView        *_header;
    FeedbackDetailTableView *_table;
    SCTypeBtn               *_succeedBtn;
    JSTextView              *_textfield;
}

@end
@implementation FeadbackDetailViewController

- (void)viewWillAppear:(BOOL)animated{

    [super viewWillAppear:animated];
    
    [_table loadDataOfNone];
}



- (void)viewDidLoad{

    [super viewDidLoad];
    
    [self setNavBarTitle:@"反馈详情"];
    
    [self buildUI];
}

- (void)viewDidDisappear:(BOOL)animated{
    [super viewDidDisappear:animated];
    
    [_table reset];
}

- (void)buildUI{

    self.view.backgroundColor = [UIColor whiteColor];
    
    _table = [[FeedbackDetailTableView alloc]initWithFrame:CGRectMake(0, 64, SIZEWIDTH, SIZEHEIGHT-64-(30+ScaleSize(27)*2)) style:UITableViewStyleGrouped];
    _table.ztid = _myModel.id;

    [self createFootView];
    [self.view addSubview:_table];
}

- (id)initDataOptionModel:(OptionModel *)model{

    _myModel = model;
        
    return self;
}
#pragma mark - --------x修改新footerview
-(void)createFootView{
    
    UIView *backView=[[UIView alloc]initWithFrame:CGRectMake(0, SIZEHEIGHT-30-ScaleSize(27)*2, SIZEWIDTH, 30+ScaleSize(27)*2)];
    
    UIView *xian = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SIZEWIDTH, 0.5)];
    xian.backgroundColor = colordbdbdb;
    [backView addSubview:xian];
    
    
    _textfield = [[JSTextView alloc]initWithFrame:CGRectMake(ScaleSize(33), ScaleSize(27), SIZEWIDTH- 50-ScaleSize(33)*2- ScaleSize(24), 30)];
    _textfield.font = NormalFont(42);
    
    _textfield.textColor = Color333333;
    _textfield.backgroundColor = BGC;
    _textfield.delegate = self;
    _textfield.layer.masksToBounds = YES;
    _textfield.layer.cornerRadius = 3;
    _textfield.layer.borderColor = colordbdbdb.CGColor;
    _textfield.layer.borderWidth = 0.5;
    
    _textfield.returnKeyType = UIReturnKeyDefault;
    //*********button**********
    _succeedBtn = [[SCTypeBtn alloc]initWithFrame:CGRectMake(SIZEWIDTH-50-ScaleSize(33), ScaleSize(27),50, 30)];
    
    [_succeedBtn setTitle:@"提交" forState:UIControlStateNormal];
    
    _succeedBtn.isCanUse = NO;
    
    [_succeedBtn addTarget:self action:@selector(loginBtnClicked) forControlEvents:UIControlEventTouchUpInside];
    
    backView.backgroundColor = [UIColor whiteColor];
    
    [self.view addSubview:backView];
    
    
    [backView addSubview:_succeedBtn];
    [backView addSubview:_textfield];

    
}
- (void)textViewDidChange:(UITextView *)textView{
    
    NSString *str = [textView.text stringByReplacingOccurrencesOfString:@" " withString:@""];
    
    if (str.length == 0) {
        
        _succeedBtn.isCanUse = NO;
        
    }else{
        
        _succeedBtn.isCanUse = YES;
    }
    
}

- (void)loginBtnClicked{

    [_textfield resignFirstResponder];
    
    NSMutableDictionary *parms = [[NSMutableDictionary alloc]init];
    [parms setObject:@"815bffb68e2ea44e38cf16a98a5a29a4" forKey:@"oauth_token"];
    [parms setObject:@"8e84bc64f03d73b5c75406ef1d7349f7" forKey:@"oauth_token_secret"];
    [parms setObject:_myModel.id forKey:@"ztid"];
    [parms setObject:_textfield.text forKey:@"hfnr"];
    
    SCHttpRequest *request = [[SCHttpRequest alloc]initWithApi:API_replyfeedback params:parms];
    [self doPOSTConnect:request start:^(SCHttpRequest * _Nonnull req) {
        
    } success:^(SCHttpRequest * _Nonnull req, SCHttpResponse * _Nonnull resp) {
        
        _textfield.text = @"";

        [_table isReloadData:YES];
        
    } failure:^(SCHttpRequest * _Nonnull req, NSError * _Nonnull error) {
        
    } finish:^(SCHttpRequest * _Nonnull req, BOOL success) {
        
    }];

}


@end
